// 删除数据
const db = wx.cloud.database();
const delData = (dataName, id, type) => {
  db.collection(dataName).doc(id).remove().then(res => {
    if (res.stats.removed > 0) {
      wx.redirectTo({
        url: '/pages/success/success?type=' + type,
      })
    }
  })
}
// 添加数据
const addData = (dataName, data, type) => {
  db.collection(dataName).add({
    data: data
  }).then(res => {
    wx.redirectTo({
      url: '/pages/success/success?type=' + type,
    })
  })
}
// 修改数据
const updateData = (dataName, id, data, type) => {
  db.collection(dataName).doc(id).update({
    data: data
  }).then(res => {
    if (res.stats.updated > 0 && type != undefined) {
      wx.redirectTo({
        url: '/pages/success/success?type=' + type,
      })
    }
  })
}
module.exports = {
  delData,
  addData,
  updateData,
}